package com.daniel.mi.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.daniel.mi.converter.UsersConverter;
import com.daniel.mi.dao.UsersDao;
import com.daniel.mi.dto.UsersDto;
import com.daniel.mi.entity.UsersEntity;
import com.daniel.mi.query.UsersQuery;
import com.daniel.mi.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.alibaba.dubbo.config.annotation.Service;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author zengneng46764
 * @Date 2024/3/6 21:54
 * @Since 1.0.0.0
 * @description:
 */

@Service
@Component
public class UsersServiceImpl implements UsersService {
    @Autowired
    private UsersDao usersDao;

    @Autowired
    private UsersConverter converter;

    @Override
    public Page<UsersDto> page(UsersQuery query) {
        Page<UsersEntity> pageReq = new Page<>(query.getPages(), query.getSize());
        QueryWrapper<UsersEntity> wrapper = converter.fromQueryToWrapper(query);
        Page<UsersEntity> responses = usersDao.page(pageReq, wrapper);
        List<UsersDto> usersDtoList = responses.getRecords().stream().map(converter::fromEntityToDto).collect(Collectors.toList());
        Page<UsersDto> results = new Page<>(query.getPages(), query.getSize(), responses.getTotal());
        results.setRecords(usersDtoList);
        return results;
    }

    @Override
    public String dubboTests(){
        return "dubbo test";
    }
}
